﻿<UserControl
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
	xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
	mc:Ignorable="d"
    xmlns:src="clr-namespace:Ec2BootstrapperGUI"
    xmlns:lib="clr-namespace:Ec2Bootstrapperlib;assembly=Ec2Bootstrapperlib"
	x:Class="Ec2BootstrapperGUI.InstanceList"
	x:Name="UserControl"
	d:DesignWidth="640" d:DesignHeight="480"
    xmlns:Ec2BootstrapperGUI="clr-namespace:Ec2BootstrapperGUI">

    <UserControl.Resources>
        <ContextMenu x:Key="ContextMenuTemplate" 
                     Style="{DynamicResource ContextMenuStyle}" 
                     Foreground="#FFFFFFFF" BitmapEffect="{DynamicResource ContextMenuDropShadow}" Margin="10">
            <MenuItem Margin="8,1,0,0" Padding="0,2,0,2" Height="30" Header="Get Administrator's Password" Click="password_Click" />
            <Separator/>
            <MenuItem Margin="8,1,0,0" Padding="0,2,2,2" Height="30" Header="Remote Connect" Click="remoteConnect_Click"/>
            <MenuItem Margin="8,1,0,0" Padding="0,2,2,2" Height="30" Header="Deploy" Click="deploy_Click" />
            <MenuItem Margin="8,1,0,0" Padding="0,2,2,2" Height="30" Header="Reboot" Click="reboot_Click" />
            <Separator />
            <MenuItem Margin="8,1,0,0" Padding="0,2,2,2" Height="30" Header="Terminate" Click="terminate_Click"/>
        </ContextMenu>
        
        <DataTemplate DataType="{x:Type lib:CEc2Instance}">
            <StackPanel Orientation="Horizontal" Margin="8">
                <StackPanel.ContextMenu>
                    <StaticResource ResourceKey="ContextMenuTemplate" />
                </StackPanel.ContextMenu>
                <!-- 
                //NOTE: If the server is running, dispaly 
                //ServerRunning resource (ServerRunning.xaml).
                //Otherwise, dispaly ServerStop resource (ServerStopped.xaml)
                -->
                <!--<Button Style="{DynamicResource ServerStopped}" Content="Button" Margin="40,0"/>-->
                <Image Source="{Binding Path=img}" Width="59" Height="107" />
                <StackPanel Width="Auto" Height="Auto">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition />
                            <RowDefinition />
                            <RowDefinition />
                            <RowDefinition />
                            <RowDefinition />
                            <RowDefinition />
                            <RowDefinition />
                            <RowDefinition />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="128"/>
                            <ColumnDefinition Width="8" />
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <TextBlock Text="Instance:" Grid.Row="0" Grid.Column="0" TextAlignment="Left"/>
                        <TextBlock Text="{Binding Path=instanceId}" TextWrapping="Wrap" Grid.Row="0" Grid.Column="2"/>
                        <TextBlock Text="Public DNS:" Grid.Row="1" Grid.Column="0" TextAlignment="Left"/>
                        <TextBlock Text="{Binding Path=publicDns}" TextWrapping="Wrap" Grid.Row="1" Grid.Column="2"/>
                        <TextBlock Text="Platform:" Grid.Row="2" Grid.Column="0" TextAlignment="Left"/>
                        <TextBlock Text="{Binding Path=platform}" TextWrapping="Wrap" Grid.Row="2" Grid.Column="2"/>
                        <TextBlock Text="AMI ID:" Grid.Row="3" Grid.Column="0" TextAlignment="Left"/>
                        <TextBlock Text="{Binding Path=imageId}" TextWrapping="Wrap" Grid.Row="3" Grid.Column="2"/>
                        <TextBlock Text="Security Groups:" Grid.Column="0" Grid.Row="4" TextAlignment="Left" FontWeight="Bold"/>
                        <TextBlock Text="{Binding Path=securityGroups}" TextWrapping="Wrap" Grid.Row="4" Grid.Column="2"/>
                        <TextBlock Text="Type:" Grid.Column="0" Grid.Row="5" TextAlignment="Left"/>
                        <TextBlock Text="{Binding Path=type}" TextWrapping="Wrap" Grid.Row="5" Grid.Column="2"/>
                        <TextBlock Text="Status:" Grid.Column="0" Grid.Row="6" TextAlignment="Left" />
                        <TextBlock Text="{Binding Path=status}" TextWrapping="Wrap" Grid.Row="6" Grid.Column="2"/>
                        <TextBlock Text="Key Pair Name:" Grid.Column="0" Grid.Row="7" TextAlignment="Left" />
                        <TextBlock Text="{Binding Path=keyPairName}" TextWrapping="Wrap" Grid.Row="7" Grid.Column="2"/>
                    </Grid>
                </StackPanel>
            </StackPanel>
        </DataTemplate>
    </UserControl.Resources>
    <Grid x:Name="LayoutRoot">
        <Rectangle Fill="{DynamicResource ContentBackgroundFill}" RadiusX="8" RadiusY="8" 
                   HorizontalAlignment="Stretch" x:Name="bkgContent" 
                   VerticalAlignment="Stretch" Width="Auto" Height="Auto" 
                   StrokeThickness="1" Stroke="{DynamicResource ContentContainerBackgroundStroke}"/>
        <ListBox Name="instancesLV" HorizontalAlignment="Stretch"
                 VerticalAlignment="Stretch" Width="Auto" Height="Auto" 
                 IsSynchronizedWithCurrentItem="True" Background="#FFC24646"
                 BorderBrush="{x:Null}" Foreground="#FFFFFFFF" 
                 ItemsSource="{Binding Path=instances, 
                        RelativeSource={RelativeSource AncestorType={x:Type src:InstanceList}},
                        Mode=OneWay}"
                 Style="{DynamicResource ListBoxStyle}" Margin="8,8,8,16" 
                 ItemContainerStyle="{DynamicResource ListBoxItemStyle}" 
                 SelectionChanged="instancesLV_SelectionChanged"/>
    </Grid>
</UserControl>